/*
 * TimeSpanForm.java
 *
 * Copyright (C) 2005 Tommi Laukkanen
 * http://www.substanceofcode.com
 *
 * Created on January 3rd 2005
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

package com.substanceofcode.carmanager.view;

import com.substanceofcode.carmanager.controller.CarManagerMIDlet;
import java.util.*;
import javax.microedition.lcdui.*;   
import com.substanceofcode.carmanager.model.SubDate;

/**
 *
 * @author Tommi Laukkanen
 */
public class TimeSpanForm extends Form implements CommandListener{
    
    private CarManagerMIDlet m_midlet = null;
    private DateField m_startDate = new DateField("Start date", DateField.DATE);
    private DateField m_endDate   = new DateField("End date",   DateField.DATE);
    private Command   m_backCommand = new Command("Back", Command.BACK, 5);
    
    /** Creates a new instance of TimeSpanForm */
    public TimeSpanForm(CarManagerMIDlet midlet) {
        super( null );
        m_midlet = midlet;
        
        Calendar calendar = Calendar.getInstance();
        SubDate yearBack = new SubDate( calendar.getTime() );
        yearBack.setYear( yearBack.getYear()-1 );
        m_startDate.setDate( yearBack.getDate() );
        m_endDate.setDate(   calendar.getTime() );
        
        this.append("Set date span");
        this.append(m_startDate);
        this.append(m_endDate);
        
        this.setCommandListener( this );
        this.addCommand( m_backCommand );
    }
    
    /** Set dates */
    public void setDates(Date start, Date end) {
        m_startDate.setDate(start);
        m_endDate.setDate(end);
    }
    
    /** Get start date */
    public Date getStartDate() {
        return m_startDate.getDate();
    }

    /** Get end date */
    public Date getEndDate() {
        return m_endDate.getDate();
    }
    
    /** Command listener acts on back command */
    public void commandAction(Command c, Displayable s) {
        if( c == m_backCommand ) {
            m_midlet.showReport();
        }
    }
    
}
